package com.haipumi.back.actions;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;

import com.haipumi.beans.DataGrid;
import com.haipumi.beans.haipumi_exchangelist;
import com.haipumi.biz.IBackExchangeBiz;
import com.haipumi.biz.impl.BackExchangeBizImpl;
import com.haipumi.servlets.CommonServlet;
import com.haipumi.utils.RequestUtil;
import com.opensymphony.xwork2.Action;

public class BackExchangeAction extends CommonServlet {
	/**
	 * 
	 */
	private static final long serialVersionUID = -7111582496084921260L;
	
	@Autowired
	IBackExchangeBiz backExchangeBiz;
	
	DataGrid dg=new DataGrid();
	
	public DataGrid getDg() {
		return dg;
	}

	public String doExchange(){
		String op=null;
		HttpServletRequest request=ServletActionContext.getRequest();
		HttpServletResponse response=ServletActionContext.getResponse();
		op=request.getParameter("op");
		if("findallexchangelist".equals(op)){
			findallexchangelist(request,response);
		}else if("updateexchangelist".equals(op)){
			updateexchangelist(request,response);
		}
		return Action.SUCCESS;
	}

	private void updateexchangelist(HttpServletRequest request,
			HttpServletResponse response) {
		haipumi_exchangelist exchangelist =RequestUtil.parseRequest(request, haipumi_exchangelist.class);
		haipumi_exchangelist backexchangelist=backExchangeBiz.updateexchangelist(exchangelist);
		super.outData(response, backexchangelist);
	}

	private void findallexchangelist(HttpServletRequest request,
			HttpServletResponse response) {
		List<haipumi_exchangelist>exchangelist=null;
		exchangelist=backExchangeBiz.findallexchangelist();
		int r=0;
		r=backExchangeBiz.countAllexchangelist();
		
		dg.setRows(exchangelist);
		dg.setTotal(r);
	}

}
